using UnityEngine;

public class Explosion : MonoBehaviour
{
	private CharacterInformation damager;

	[SerializeField]
	private ParticleSystem particle;

	public AudioSource source;

	public float radius;

	public float force;

	public float damage;

	public float screenShakeForce;

	public bool spam;

	public float stopAfter;

	public void SetDamager(CharacterInformation info, float damage)
	{
		damager = info;
		this.damage = damage;
	}

	private void FixedUpdate()
	{
		stopAfter -= Time.deltaTime;
		if (spam && stopAfter > 0f)
		{
			Explode();
		}
	}

	public void Explode()
	{
		if (PersistenData.Sound)
		{
			source.Play();
		}
		base.transform.parent = null;
		UnityEngine.Object.Destroy(base.gameObject, 5f);
		particle.Play();
		Collider[] array = Physics.OverlapSphere(base.transform.position, radius);
		foreach (Collider collider in array)
		{
			Rigidbody component = collider.gameObject.GetComponent<Rigidbody>();
			if (component != null)
			{
				float num = Mathf.Clamp(component.mass / 500f, 0.01f, 1f);
				component.AddExplosionForce(force * num, base.transform.position, radius, 1f, ForceMode.Impulse);
			}
			CharacterPart component2 = collider.gameObject.GetComponent<CharacterPart>();
			if ((bool)component2 && damage > 0f)
			{
				float num2 = (radius - Vector3.Distance(base.transform.position, component2.transform.position)) / radius;
				float num3 = damage * num2;
				component2.TakeDamage(num3, damager, Vector3.zero);
			}
			BombCrate component3 = collider.gameObject.GetComponent<BombCrate>();
			if (component3 != null)
			{
				component3.Blow(damager);
			}
		}
		CameraShakeController.Instance.AddShake(Vector3.up * 4f);
	}
}
